#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/mman.h>

int main()
{
    int fd;
    void *start_fp;

    if ( (fd = open("./file", O_RDWR|O_CREAT, S_IRWXU)) < 0){
        printf("open file wrong!");
        exit(1);
    }

    struct stat file_stat;
    if ( fstat( fd, &file_stat) < 0 )
    {
        printf(" fstat wrong");
        exit(1);
    }


    if (( start_fp = mmap(NULL, file_stat.st_size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0 )) == MAP_FAILED)
    {
        printf("mmap wrong");
        exit(0);
    }

    snprintf( (char *)start_fp, 10, "helloworld");
    msync( start_fp, file_stat.st_size, MS_ASYNC);

    if ( munmap( start_fp, file_stat.st_size ) < 0 )
    {
        printf("munmap wrong");
        exit(1);
    }
}
